<script type="text/javascript">
	$(document).ready(function() {
		var a = '${flightId}';
		var notyId = "\"" + a + "\"";
		if($('[id=' + notyId + ']').length>0){
			$('html, body').animate({
				scrollTop : $('[id=' + notyId + ']').offset().top - 75
			}, 800);
			$('[id=' + notyId + ']').delay(800).animate({
				left : '5px',
				backgroundColor : '#fffca0'
			}, 250, function() {
				$('[id=' + notyId + ']').css("background-color", "#fffca0");
			});
			$('[id=' + notyId + ']').delay(50).animate({
				opacity : "0.5",
				left : '0px',
				backgroundColor : '#FFFFFF'
			}, 250, function() {
				$('[id=' + notyId + ']').css("background-color", "#FFFFFF");
				$('[id=' + notyId + ']').css("opacity", "1");
			});
		}else 
			if(a!=''){
				generate('error', "The subscribed flight has been deleted");
			}
	});

	function requestUnsubsribe(flightId, index) {
				$.confirm({
					'title' : 'UNSUBSCRIBE',
					'message' : 'Do you really want to delete this subscribed flight?',
					'buttons' : {
						'No' : {
							'action' : function() {
								$("#confirmBox").slideUp();
							} // Nothing to do in this case. You can as well omit the action property.
						},
						'Yes' : {
							'action' : function() {
								$("#confirmBox").slideUp();

								//show loading panel in jsloading.jsp
								showLoading();

								controller_url = "${pageContext.request.contextPath}/subscribe/unsubscribe.html";

								var json = {
									"flightId" : flightId
								};

								$
										.ajax({
											url : controller_url,
											data : JSON.stringify(json),
											type : 'POST',
											dataType : "text",
											beforeSend : function(xhr) {
												xhr.setRequestHeader("Accept",
														"application/json");
												xhr.setRequestHeader(
														"Content-Type",
														"application/json");
											},
											success : function(string) {
												unShowLoading();
												// Callback to atmostphere
												$("#flight" + index).slideUp();
												$("#br" + index).slideUp();

												setTimeout(
														function() {
															$("#flight" + index)
																	.remove();
															$("#br" + index)
																	.remove();

															function stickyFooter() {
																var footer = $("#footer");
																var pos = footer
																		.position();
																var height = $(
																		window)
																		.height();
																height = height
																		- pos.top;
																height = height
																		- footer
																				.outerHeight();

																if (height > 0) {
																	footer
																			.css({
																				'margin-top' : height
																						+ 'px'
																			});
																}
															}
															;
															stickyFooter();

															var noOfFlight = $(
																	".subscribed-flight")
																	.size();

															var msg1 = '<span class="subscribed">YOU HAVE </span>';
															var msg = '';
															msg += msg1;
															if (noOfFlight == 0) {
																msg += '<span class="subscribed">NOT YET SUBSCRIBED ANY FLIGHT!</span>';
															} else {
																msg += '<span class="subscribed-number">'
																		+ noOfFlight
																		+ '</span><span class="subscribed-number"> SUBSCRIBED FLIGHT(S)</span>';
															}
															// 								$("#subscribe-list").html(msg);
															$("#subscribe-list")
																	.empty()
																	.append(msg);

															message = "You unsubscribed this flight successfully.";
															generate('success', message);
														}, 0);

											},
											error : function(string, status, er) {
												$.confirm({
															'title' : 'UNSUBSCRIBE',
															'message' : 'Error happened!',
															'buttons' : {
																'OK' : {
																	'action' : function() {
																		$(
																				"#confirmBox")
																				.slideUp();
																	} // Nothing to do in this case. You can as well omit the action property.
																}
															}
														});
											}
										});
							}
						}
					}
				});
	}
</script>